package com.engine4cloud.tdf.supervision.controller.web;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.create.JzdxReleaseCreateDTO;
import com.engine4cloud.tdf.supervision.dto.result.JzdxReleaseResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.JzdxReleaseUpdateDTO;
import com.engine4cloud.tdf.supervision.service.JzdxReleaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 矫正对象-解除（终止）-web
 *
 * @author wenjie
 * @date 2024-04-11 17:40:57
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/corrector/release")
@Tag(description = "correctorRelease", name = "矫正对象-解除（终止）-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class JzdxReleaseWebController {

    private final JzdxReleaseService jzdxReleaseService;

    /**
     * 查询解矫信息
     *
     * @param code 矫正对象编号
     * @return R<PageInfo < JzdxReleaseResultDTO>>
     */
    @Operation(summary = "查询解矫信息", description = "查询解矫信息")
    @GetMapping("/find")
    public R<JzdxReleaseResultDTO> find(@Schema(description = "矫正对象编号") String code) {
        return R.ok(jzdxReleaseService.findByCode(code));
    }

    /**
     * 通过id查询矫正对象-解除
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<JzdxReleaseResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(jzdxReleaseService.getById(id));
    }

    /**
     * 新增矫正对象-解除
     *
     * @param dto 矫正对象-解除
     * @return R
     */
    @Operation(summary = "新增矫正对象-解除", description = "新增矫正对象-解除")
    @SysLog("新增矫正对象-解除")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('correct_release_add')")
    public R<Boolean> create(@Valid @RequestBody JzdxReleaseCreateDTO dto) {
        return R.ok(jzdxReleaseService.create(dto));
    }

    /**
     * 修改矫正对象-解除
     *
     * @param dto 矫正对象-解除
     * @return R
     */
    @Operation(summary = "修改矫正对象-解除", description = "修改矫正对象-解除")
    @SysLog("修改矫正对象-解除")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('correct_release_edit')")
    public R<Boolean> update(@Valid @RequestBody JzdxReleaseUpdateDTO dto) {
        return R.ok(jzdxReleaseService.update(dto));
    }

    /**
     * 通过id删除矫正对象-解除
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除矫正对象-解除", description = "通过id删除矫正对象-解除")
    @SysLog("通过id删除矫正对象-解除")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('correct_release_del')")
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(jzdxReleaseService.removeBatchByIds(CollUtil.toList(ids)));
    }

}